package org.skywork.top.ai.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AiController {

    private final ChatClient chatClient;

    public AiController(ChatClient.Builder builder) {
        // 给模型system一个角色，便于生成更准确的回答
        this.chatClient = builder.
                defaultSystem("你是一个炒股方向技术精湛的专家，我经常会想你提问一些股票方面的问题，你总是能给我详细的答案。").
                build();
    }

    @GetMapping("/chat/{prompt}")
    public String chat(@PathVariable("prompt") String prompt) {
        return chatClient.prompt()
                // 提问语
                .user(prompt)
                .call()
                .content();
    }
}
